package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.ClubRegistration;
import com.atguigu.srb.core.service.ClubRegistrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
*社团报名
 * </p>
 *
 * @author Helen
 * @since 2021-02-20
 */
@Api(tags = "社团报名管理")
@CrossOrigin
@RestController
@RequestMapping("/admin/core/clubregistration")
@Slf4j
public class ClubRegistrationController {

    @Resource
    private ClubRegistrationService clubRegistrationService;

    @ApiOperation(value = "根据id删除数据记录", notes="逻辑删除数据记录")
    @DeleteMapping("/remove/{club_registration_id}")
    public R removeById(
            @ApiParam(value = "社团报名的id")
            @PathVariable int club_registration_id){

        boolean result = clubRegistrationService.removeById(club_registration_id);
        if(result){
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }

    @ApiOperation("增加社团报名")
    @PostMapping("/save")
    public R save(
            @ApiParam(value = "社团报名表",required = true)
            @RequestBody ClubRegistration clubRegistration
            ){
                  boolean result = clubRegistrationService.save(clubRegistration);
        if(result){
            return R.ok().message("保存成功");
        }else{
            return R.error().message("保存失败");
        }
    }
    @ApiOperation("社团报名列表")
    @GetMapping("/list")
    public  R listAll(){
        List<ClubRegistration> list = clubRegistrationService.list();

        return R.ok().data("list",list);

    }

    @ApiOperation("根据id获取社团报名表")
    @GetMapping("/get/{club_registration_id}")
    public R getById(
            @ApiParam(value = "数据id", required = true, example = "1")
            @PathVariable int club_registration_id){

        ClubRegistration clubRegistration = clubRegistrationService.getById(club_registration_id);
        if(clubRegistration != null){
            return R.ok().data("record",clubRegistration);
        }else{
            return R.error().message("数据获取失败");
        }
    }
}
